package com.code;

import com.landmesure.settings.fragment.argsinfo.ArgumentsInfo;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/4/3 0003.
 */
public class PropertyDefinition implements Cloneable{
    protected  int code;//参数编码
    protected int dataLength;//参数长度
    protected int decimalLength;//小数位数
    protected List<EnumValue> enumValues;//枚举集合
    protected boolean enumable;//是否枚举，
    protected String group;//参数类型
    protected String name;//参数名
    protected boolean readOnly=false;//是否只读
    protected boolean remoteSup;
    protected String unit;//单位
    protected String value;//参数值
    protected String vtype;//参数类型

    public String getVtype() {
        return vtype;
    }

    public void setVtype(String vtype) {
        this.vtype = vtype;
    }

    public int getDecimalLength() {
        return decimalLength;
    }

    public void setDecimalLength(int decimalLength) {
        this.decimalLength = decimalLength;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public int getDataLength() {
        return dataLength;
    }

    public void setDataLength(int dataLength) {
        this.dataLength = dataLength;
    }

    public List<EnumValue> getEnumValues() {
        return enumValues;
    }

    public void setEnumValues(List<EnumValue> enumValues) {
        this.enumValues = enumValues;
    }

    public boolean isEnumable() {
        return enumable;
    }

    public void setEnumable(boolean enumable) {
        this.enumable = enumable;
    }

    public String getGroup() {
        return group;
    }

    public void setGroup(String group) {
        this.group = group;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public boolean isReadOnly() {
        return readOnly;
    }

    public void setReadOnly(boolean readOnly) {
        this.readOnly = readOnly;
    }

    public boolean isRemoteSup() {
        return remoteSup;
    }

    public void setRemoteSup(boolean remoteSup) {
        this.remoteSup = remoteSup;
    }

    public String getUnit() {
        return unit;
    }

    public void setUnit(String unit) {
        this.unit = unit;
    }

    @Override
    public Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
    /**
     * 转换为ArgumentsInfo结构;
     */
    public ArgumentsInfo copySelf() {
        if (enumable) {
            ArrayList<String> selects = new ArrayList<>();
            int index = 0;
            int i = 0;
            for (EnumValue v : enumValues) {
                selects.add(v.getValue());
                if (null != value) {
                    if (value.equals(v.getCode())) {
                        index = i;
                    }
                }
                i++;
            }
            if (selects.isEmpty()) {
                return new ArgumentsInfo(vtype, name, value, unit, group,
                        String.valueOf(code), readOnly, enumable, selects, "");
            }
            return new ArgumentsInfo(vtype, name, value, unit, group,
                    String.valueOf(code), readOnly, enumable, selects, selects.get(index));
        } else {
            return new ArgumentsInfo(vtype, name, value, unit, group, String.valueOf(code), readOnly);
        }
    }

}
